﻿using System;
using System.Windows.Threading;

namespace XamlingCore.Infrastructure.Callbacks
{
    public class TimeoutCallback
    {
        public static void Callback(TimeSpan ts, Action callback)
        {
            DispatcherTimer t = new DispatcherTimer();
            t.Interval = ts;
            t.Tick += (s, e) =>
                          {
                              t.Stop();
                              t = null;
                              callback();
                          };
            t.Start();
        }

        public static void RepeatCallback(TimeSpan ts, Action callback)
        {
            DispatcherTimer t = new DispatcherTimer();
            t.Interval = ts;
            t.Tick += (s, e) =>
            {
                callback();
            };
            t.Start();
        }
    }
}
